package com.fieldchain.ex.fa100.ui.personal.activity;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.base.MyBaseActivity;
import com.fieldchain.ex.fa100.bean.User;

import com.fieldchain.ex.fa100.utils.share.ShareManager;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/14
 */
public class  SafeActivity extends MyBaseActivity implements View.OnClickListener {
    private RelativeLayout reaBack;
    private TextView tvCenter;
    private RelativeLayout reaPhone;
    private TextView tvPhone;
    private RelativeLayout reaEmail;
    private TextView tvEmail;
    private RelativeLayout reaLoginpwd;
    private TextView tvLoginpwd;
    private RelativeLayout reaTradpwd;
    private TextView tvTradpwd;

    private User user;
    private String bind = "绑定";
    private String unBind = "未绑定";
    private String change = "修改";
    private String set = "设置";

    private boolean[] tags = new boolean[3];

    @Override
    public void findView() {
        reaBack = findViewById(R.id.rea_back);
        tvCenter = findViewById(R.id.tv_center);
        reaPhone = findViewById(R.id.rea_phone);
        tvPhone = findViewById(R.id.tv_phone);
        reaEmail = findViewById(R.id.rea_email);
        tvEmail = findViewById(R.id.tv_email);
        reaLoginpwd = findViewById(R.id.rea_loginpwd);
        tvLoginpwd = findViewById(R.id.tv_loginpwd);
        reaTradpwd = findViewById(R.id.rea_tradpwd);
        tvTradpwd = findViewById(R.id.tv_tradpwd);
    }

    @Override
    public void setValue() {
        checkUser();
        tvCenter.setText("安全中心");
        reaBack.setOnClickListener(this);
        reaPhone.setOnClickListener(this);
        reaEmail.setOnClickListener(this);
        reaLoginpwd.setOnClickListener(this);
        reaTradpwd.setOnClickListener(this);
    }


    @Override
    public int getLayout() {
        return R.layout.activity_safe;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rea_back:
                finish();
                break;
            case R.id.rea_phone:
                if (tags[0]) {
//                    startActivity(new Intent(mContext,ChangePhoneActivity.class));
//                    finish();
                } else {
                    startActivity(new Intent(mContext,SafeBindPhoneActivity.class));
                    finish();
                }
                break;
            case R.id.rea_email:
                if (tags[1]) {
                    startActivity(new Intent(mContext,ChangeEmailctivity.class));
                    finish();
                } else {
                    startActivity(new Intent(mContext,SafeBindEmailActivity.class));
                    finish();
                }
                break;
            case R.id.rea_loginpwd:
                startActivity(new Intent(mContext,ChangeLoginPwdActivity.class));
                finish();
                break;
            case R.id.rea_tradpwd:
//                if(tags[2]) {
//                    startActivity(new Intent(mContext, ChangeTradPwdActivity.class));
//                    finish();
//                }else{
//
//                }
                startActivity(new Intent(mContext, SetTradPwdActivity.class));
                finish();
                break;

        }
    }

    private void checkUser() {
        user = ShareManager.getInstance().getUser();
        String phone = user.getPhone()!=null?user.getPhone():"";
        String email = user.getEmail()!=null?user.getEmail():"";
        boolean hadPwd = user.getTpwFlag() == 1 ? true : false;
        if (phone.length() > 0) {
            tvPhone.setText(phone);
            tags[0] = true;
        } else {
            tvPhone.setText(bind);
        }

        if (email.length() > 0) {
            tvEmail.setText(change);
            tags[1] = true;
        } else {
            tvEmail.setText(bind);
        }
        if (hadPwd) {
            tags[2] = true;
            tvTradpwd.setText(change);
        } else {
            tvTradpwd.setText(set);
        }
    }


}
